package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type OnlineEventSupportLog struct {
	ID        string `json:"id" gorm:"primaryKey;column:id;autoIncrement;type:bigint"`
	SupportID string `json:"support_id" gorm:"column:support_id;type:int;size:64;uniqueIndex:uk_support,priority:1"`
	OpenID    string `json:"openid" gorm:"column:openid;type:string;size:40;uniqueIndex:uk_support,priority:2;comment:助力用户openid"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;index:idx_createdAt"`
}

func (OnlineEventSupportLog) TableName() string {
	return "online_event_support_log"
}

// BeforeCreate 自增id
func (m *OnlineEventSupportLog) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &OnlineEventSupportLog{})
}
